package com.wx.mall.sys.controller;


import com.wx.mall.common.api.CommonPage;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.common.api.PageVo;
import com.wx.mall.sys.entity.LoginLog;
import com.wx.mall.sys.service.ILoginLogService;
import com.wx.mall.common.vo.sys.LoginLogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 登录日志 前端控制器
 * </p>
 *
 * @author ljl
 * @since 2020-03-30
 */
@RestController
@RequestMapping("/login-log")
@Api(tags = "登录日志相关接口")
public class LoginLogController {
    @Autowired
    private ILoginLogService service;

    @GetMapping("/loginLogs")
    @ApiOperation("分页获取日志信息列表")
    public CommonResult add(@ApiParam("区域vo")@Valid PageVo vo) {
        CommonPage<LoginLog> page = service.pageList(vo);
        return CommonResult.success(page);
    }

    @GetMapping("/loginLog")
    @ApiOperation("新增登录日志")
    public CommonResult add(@Valid LoginLogVO vo) {
//        String ip = (String) request.getAttribute("ip");
        Integer save = service.save(vo);
        if (save == 0){
            return CommonResult.failed("添加登录日志失败。");
        }
        return CommonResult.success();
    }


//    @GetMapping("/areas/{tier}")
//    @ApiOperation("根据tier获取顶级到tier层级的所有区域列表")
//    public DataResult findAllByTier(@ApiParam("区域层级tier") @PathVariable("tier") @NotNull(message = "区域tier不能为空") Integer tier) {
//        List<AreaRespVO> areas = areaService.getAreasByTier(tier);
//        return DataResult.success(areas);
//    }
}

